<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://users">

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/form.xsl" />
	<xsl:include href="../photos/blocks.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/user-profile.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/users.js" />
			<script type="text/javascript" src="{$baseURI}/js/twitter.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
					<h4>&labelBlockAlbums;</h4>
					<p>
						<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbums/', response/@user-id))/data/response" mode="block-user-albums" />
					</p>
				</div>
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response/object[@type='user']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="login" select="property[@name='login']/value" />
		<xsl:param name="typeId" select="@type-id" />
		<xsl:param name="allowVote" select="@vote-allowed" />
		
		<table cellspacing="0" cellpadding="0" id="t_profile">
			<tr>
				<td id="profile_left">
					<div id="profile_avatar_wrap">
						<img>
							<xsl:attribute name="src">
								<xsl:if test="property[@name='avatar']/value != ''">
									<xsl:value-of select="concat ($baseURI, property[@name='avatar']/value)" />
								</xsl:if>
								<xsl:if test="property[@name='avatar']/value = ''">
									<xsl:value-of select="concat ($baseURI, '/images/default-avatar.png')" />
								</xsl:if>
							</xsl:attribute>
							<xsl:attribute name="alt">
								<xsl:value-of select="property[@name='name']/value" />
							</xsl:attribute>
						</img>
						
						<div id="user_ratig">
							<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id, ';1'))/data/response/vote" mode="user-vote" />
							<span id="ratind_votes">― <xsl:value-of select="php:functionString ('XSLTGetNumWithCase', property[@name='rating_votes']/value, '&labelVotePad1;', '&labelVotePad2;', '&labelVotePad3;')" /></span>
						</div>
						
					</div>
				</td>
				<td id="profile_right">
					<h1 id="user_name">
						<xsl:value-of select="property[@name='name']/value" />
						<xsl:if test="$userId = @id">
							<xsl:text> — &labelIm;</xsl:text>
						</xsl:if>
						
						<xsl:if test="@id != $userId and $userGroup != 'guest'">
							<a id="user_friend" href="javascript:void(0)" onclick="setFriend ({@id}, '{$login}'); return false;">
								<xsl:if test="@friend = '0'">
									<xsl:attribute name="title">&labelAddFriend;</xsl:attribute>
									<img src="{$baseURI}/images/big-plus-green.png" alt="" />
								</xsl:if>
								<xsl:if test="@friend = '1'">
									<xsl:attribute name="title">&labelRemoveFriend;</xsl:attribute>
									<img src="{$baseURI}/images/big-plus-red.png" alt="" />
								</xsl:if>
							</a>
							
							<a id="mail_friend">
								<xsl:if test="@friend = '1'">
									<xsl:attribute name="title">&labelSendMessage;</xsl:attribute>
									<xsl:attribute name="href">
										<xsl:value-of select="concat ($baseURI, '/mail/write?to=', @id)" />
									</xsl:attribute>
									<img src="{$baseURI}/images/big-send-mail-active.png" alt="" />
								</xsl:if>
								<xsl:if test="@friend = '0'">
									<img src="{$baseURI}/images/big-send-mail-not-active.png" alt="" />
								</xsl:if>
							</a>
						</xsl:if>
					</h1>
					
					<xsl:if test="property[@name='twitter_login']/value != ''">
						<script type="text/javascript">
							twitter_status('<xsl:value-of select="property[@name='twitter_login']/value" />','twitter_status');
						</script>
						<div id="twitter_status" />
					</xsl:if>
					
					<div id="profile_nav">
						<a class="selected" href="{$baseURI}/users/profile/{$login}">&labelUserProfile;</a>
						<a href="{$baseURI}/blogs/user/{$login}">&labelUserBlog;</a>
						<a href="{$baseURI}/photos/user/{$login}">&labelUserPhotos;</a>
						<a href="{$baseURI}/comments/user/{$login}">&labelUserComments;</a>
					</div>
					<div id="user_properties">
						<xsl:apply-templates select="property" />
						
						<xsl:apply-templates select="document(concat('xmodule://users/getFriendsList/', @id))/data/response" mode="friends" />
												
						<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id))/data/response" mode="joined-blogs" />
						
						<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id, ';moderator'))/data/response" mode="moderate-blogs" />
						
						<xsl:apply-templates select="document(concat('xmodule://blogs/getJoinBlogsList/', @id, ';admin'))/data/response" mode="admin-blogs" />
					</div>
				</td>
			</tr>
		</table>
	</xsl:template>
	
	<xsl:template match="property[@name='login']" />
	<xsl:template match="property[@name='password']" />
	<xsl:template match="property[@name='group']" />
	<xsl:template match="property[@name='avatar']" />
	<xsl:template match="property[@name='name']" />
	<xsl:template match="property[@name='email']" />
	<xsl:template match="property[@name='rating']" />
	<xsl:template match="property[@name='rating_votes']" />
	<xsl:template match="property[@name='interests']" />
	<xsl:template match="property[@name='count_friends']" />
	
	<xsl:template match="response" mode="joined-blogs">
		<xsl:if test="count(object) != 0">
			<div class="property_item">
				<div class="property_title">&labelHeRead;:</div>
				<div class="property_value">
					<ul id="blogs_list">
						<xsl:apply-templates select="object" mode="blogs" />
					</ul>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="response" mode="moderate-blogs">
		<xsl:if test="count(object) != 0">
			<div class="property_item">
				<div class="property_title">&labelHeModerate;:</div>
				<div class="property_value">
					<ul id="blogs_list">
						<xsl:apply-templates select="object" mode="blogs" />
					</ul>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="response" mode="admin-blogs">
		<xsl:if test="count(object) != 0">
			<div class="property_item">
				<div class="property_title">&labelHeAdmin;:</div>
				<div class="property_value">
					<ul id="blogs_list">
						<xsl:apply-templates select="object" mode="blogs" />
					</ul>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='livejournal_login']">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<a class="livejournal">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://', value,'.livejournal.com')" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='twitter_login']">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<a class="twitter">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://twitter.com/', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='habr_login']">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<a class="habr">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://', value, '.habrahabr.ru')" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='vkontakte_id']">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<a class="vkontakte">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://vkontakte.ru/id', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='icq']">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<a class="icq">
						<xsl:attribute name="href">
							<xsl:value-of select="concat ('http://wwp.icq.com/scripts/contact.dll?msgto=', value)" />
						</xsl:attribute>
						<xsl:value-of select="value" />
					</a>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='interests']">
		<xsl:param name="cnt" select="count (value)" />
		
		<xsl:if test="$cnt &gt; 0">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<xsl:for-each select="value">
						<xsl:value-of select="." />
						<xsl:if test="position() != $cnt">
							<xsl:text>, </xsl:text>
						</xsl:if> 
					</xsl:for-each>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property[@name='gender']">
		<xsl:param name="cnt" select="count (value)" />
		
		<xsl:if test="$cnt &gt; 0">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" /><xsl:text>:</xsl:text>
				</div>
				<div class="property_value">
					<xsl:choose>
						<xsl:when test="value = 'man'">
							<xsl:text>&labelMan;</xsl:text>
						</xsl:when>
						<xsl:when test="value = 'woman'">
							<xsl:text>&labelWoman;</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>&labelNoGender;</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="property">
		<xsl:if test="value != ''">
			<div class="property_item">
				<div class="property_title">
					<xsl:value-of select="title" />:
				</div>
				<div class="property_value">
					<xsl:value-of select="value" />
				</div>
			</div>
		</xsl:if>
	</xsl:template>
	
	<!-- USER VOTE -->
	<xsl:template match="vote" mode="user-vote">
		<xsl:param name="id" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="typeId" select="type_id" />
		<xsl:param name="rating" select="rating" />
		
			<xsl:choose> 
				<xsl:when test="$allow = '1' and $vote = ''">
					<a id="arrow_up_rating" title="&labelVoteUp;" class="vote good" href="javascript:void(0)">
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('voteUser (', $id,', 1)')" />
						</xsl:attribute>
						<xsl:text>↑</xsl:text>
					</a>
				</xsl:when>
				<xsl:when test="$vote = '1' and $allow = '0'">
					<a href="javascript:void(0)" class="vote good" onclick="new Error ('&labelCantVoteAgain;');">↑</a>
				</xsl:when>
				<xsl:when test="$vote = '0' and $allow = '0'">
					<a href="javascript:void(0)" class="vote cant" onclick="new Error ('&labelCantVoteAgain;');">↑</a>
				</xsl:when>
				<xsl:otherwise>
					<a href="javascript:void(0)" class="vote cant" onclick="new Error ('&labelCantVote;');">↑</a>
				</xsl:otherwise>
			</xsl:choose>
			<span id="rating_number"><xsl:value-of select="$rating" /></span>
			<xsl:choose>
				<xsl:when test="$allow = '1' and $vote = ''">
					<a id="arrow_down_rating" title="&labelVoteDown;" class="vote bad" href="javascript:void(0)">
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('voteUser (', $id,', 0)')" />
						</xsl:attribute>
						<xsl:text>↓</xsl:text>
					</a>
				</xsl:when>
				<xsl:when test="$vote = '1' and $allow = '0'">
					<a href="javascript:void(0)" class="vote cant" onclick="new Error ('&labelCantVoteAgain;');">↓</a>
				</xsl:when>
				<xsl:when test="$vote = '0' and $allow = '0'">
					<a href="javascript:void(0)" class="vote bad" onclick="new Error ('&labelCantVoteAgain;');">↓</a>
				</xsl:when>
				<xsl:otherwise>
					<a href="javascript:void(0)" class="vote cant" onclick="new Error ('&labelCantVote;');">↓</a>
				</xsl:otherwise>
			</xsl:choose>
	</xsl:template>
	
	<!-- FRIENDS -->
	<xsl:template match="response" mode="friends">
		<div class="property_item">
			<div class="property_title">&labelFriends;:</div>
			<div class="property_value">
				<xsl:if test="count (object) = 0">
					<xsl:text>&labelNoneFriends;</xsl:text>
				</xsl:if>
				<xsl:if test="count (object) &gt; 0">
					<ul id="friends_list">
						<xsl:apply-templates select="object" mode="friend-item" />
					</ul>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='friend']" mode="friend-item">
		<li>
			<a>
				<xsl:attribute name="href">
					<xsl:value-of select="concat ($baseURI, '/user/', property[@name='user_login']/value)" />
				</xsl:attribute>
				<xsl:value-of select="property[@name='user_name']/value" />
			</a>
		</li>
	</xsl:template>
	
	<!-- JOINED BLOG -->
	<xsl:template match="object[@type='blog_member' or @type='blog_moderator' or @type='blog_admin']" mode="blogs">
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<li>
			<a href="{$baseURI}/blog/{$blogAlias}">
				<xsl:value-of select="property[@name='blog_title']/value" />
			</a>
		</li>
	</xsl:template>
	
</xsl:stylesheet>